<template>
  <div class="login">
    <div class="ms-login">
      <div class="ms-login2">
        <div class="p">
          <p class="p1">
            欢迎来到
            <img src="../assets/image/share.png" />
          </p>
          <p class="p2">大恒集团管理平台系统</p>
        </div>
      </div>

      <div class="ms-login3">
        <!-- <img
          src="../assets/image/erweibtn.png"
          @click="change"
          :style="{top:height2+ 'px'}"
          alt
          sizes
          srcset
        /> -->
        <el-carousel
          height="520px"
          interval:4000
          direction="vertical"
          :autoplay="false"
          ref="carousel"
          initial-index:0
          trigger="click"
        >
          <el-carousel-item>
            <div>
              <div class="ms-title">
                <p class="p3">Welcome,</p>
                <p class="p4">大恒集团管理平台系统</p>
                <!-- <p class="p5">扫描下载手机端APP</p> -->
              </div>
              <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
                <el-form-item prop="username">
                  <el-input
                    v-model="loginForm.username"
                    type="text"
                    auto-complete="off"
                    placeholder="账号"
                  >
                    <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
                  </el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input
                    v-model="loginForm.password"
                    type="password"
                    auto-complete="off"
                    placeholder="密码"
                    @keyup.enter.native="handleLogin"
                  >
                    <svg-icon
                      slot="prefix"
                      icon-class="password"
                      class="el-input__icon input-icon"
                    />
                  </el-input>
                </el-form-item>
                <!-- <el-form-item prop="code">
                  <el-input
                    v-model="loginForm.code"
                    auto-complete="off"
                    placeholder="验证码"
                    style="width: 63%"
                    @keyup.enter.native="handleLogin"
                  >
                    <svg-icon
                      slot="prefix"
                      icon-class="validCode"
                      class="el-input__icon input-icon"
                    />
                  </el-input>
                  <div class="login-code2">
                    <img :src="codeUrl" @click="getCode" class="login-code-img2" />
                  </div>
                </el-form-item> -->
                <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
                <el-form-item class="login-btn">
                  <el-button
                    :loading="loading"
                    size="medium"
                    type="primary"
                    @click.native.prevent="handleLogin"
                    style="width:100%;height:50px;font-size:20px;background-color: #0C5987;"
                  >
                    <span v-if="!loading">登 录</span>
                    <span v-else>登 录 中...</span>
                  </el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-carousel-item>
          <!-- <el-carousel-item>
            <div class="img-erweima">
              <p class="p5">扫描安装云呼小程序</p>
              <img src="http://crm.saipaisi.cn:8088//mnt/crm/appimg/appinfo.png" alt sizes srcset />
            </div>
          </el-carousel-item> -->
        </el-carousel>
      </div>
    </div>
  </div>
</template>

<script>
import { getPics } from "@/api/login";
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";
export default {
  name: "Login",
  data() {
    return {
      pics:'',
      height2: 0,
      codeUrl: "",
      cookiePassword: "",
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: "",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" },
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" },
        ],
        code: [
          { required: true, trigger: "change", message: "验证码不能为空" },
        ],
      },
      loading: false,
      redirect: undefined,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true,
    },
  },
  created() {
    // this.getCode();
    this.getCookie();
  },
  methods: {
    getPics(){
      getPics({
        relationId:1,
        type:"QRcode"
      }).then((res)=>{
        this.pics=res.data[0].url
      })
    },
    change() {
      if (this.blue) {
        this.$refs.carousel.setActiveItem(1);
        this.blue = false;
        this.height2 = -55;
        console.log("error submit!!");
      } else {
        this.$refs.carousel.setActiveItem(0);
        this.blue = true;
        this.height2 = 0;
      }
    },
    // getCode() {
    //   getCodeImg().then((res) => {
    //     this.codeUrl = "data:image/gif;base64," + res.img;
    //     this.loginForm.uuid = res.uuid;
    //   });
    // },
    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get("rememberMe");
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password:
          password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
      };
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), {
              expires: 30,
            });
            Cookies.set("rememberMe", this.loginForm.rememberMe, {
              expires: 30,
            });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove("rememberMe");
          }
          this.$store
            .dispatch("Login", this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" });
            })
            .catch(() => {
              this.loading = false;
              this.getCode();
            });
        }
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}


.login {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url("../assets/image/login-background.png");
  background-size: cover;
  background-position: center center;
}

.ms-title {
  width: 100%;
  color: #0c5987;
  display: inline-block;
  .p3 {
    font-size: 46px;
    font-weight: 550;
    margin-top: 20px;
  }
  .p4 {
    font-size: 32px;
  }
  .p5 {
    font-size: 22px;
    text-align: right;
    margin-top: 10px;
    // margin-bottom: 20px;
    box-sizing: border-box;
    padding: 0 30px;
  }
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1200px;
  height: 550px;
  transform: translate(-50%, -50%);
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
}
.ms-login2 {
  width: 600px;
  height: 550px;
  border-radius: 5px 0 0 5px;
  background-color: black;
  opacity: 0.5;
  color: #ffffff;
  padding: 0px 50px 0px 50px;
  position: relative;
  .p {
    margin-top: 190px;
    .p1 {
      font-size: 34px;
      border-bottom: 1px solid #ffffff;
      display: flex;
      align-items: center;
      padding: 5px 0;
      img {
        display: inline-block;
        width: 40px;
        height: 40px;
        margin-left: 10px;
      }
    }
    .p2 {
      font-size: 34px;
      display: flex;
      align-items: center;
    }
  }
}

.ms-login3 {
  width: 600px;
  height: 550px;
  border-radius: 0 5px 5px 0;
  background-color: #ffffff;
  padding: 0px 60px 0px 60px;
  box-sizing: border-box;
  position: relative;
  img {
    display: block;
    width: 110px;
    height: 150px;
    position: absolute;
    right: -3px;
    transition: all 0.4s;
  }
}

.ms-content {
  padding: 30px 30px;
}
.login-btn {
  text-align: center;
  margin-top: 30px;
}
.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}
.el-checkbox__input.is-checked .el-checkbox__inner,
.el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background-color: #0c5987 !important;
  border-color: #0c5987 !important;
}
.el-checkbox__input.is-checked + .el-checkbox__label {
  color: #0c5987 !important;
}
.el-checkbox .is-bordered.is-checked {
  border-color: #0c5987 !important;
}
.el-checkbox__input .is-focus .el-checkbox__inner {
  border-color: #0c5987 !important;
}
.login-password button {
  float: right;
}
.login-code2 {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
  .login-code-img2 {
  display: inline-block;
  // width: 33%!important;
  height: 38px;
}
}

/* .title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}

i {
  font-size: 14px;
  margin-left: 8px;
}
.forget {
  float: right;
}
 */
.img-erweima {
  width: 440px;
  height: 520px;
  position: relative;
  img {
    width: 250px;
    height: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .p5 {
    width: 100%;
    font-size: 30px;
    text-align: center;
    // margin-top: 60px;
    // margin-bottom: 20px;
    box-sizing: border-box;
    padding: 50px 30px;
    color: #0c5987;
  }
}
</style>
